function [imgFV, dbn] = fvLearnDBN( img, rf, params)

img = double(img);
[H,W,Band] = size(img);

if max(max(max(img))) > 1 || min(min(min(img))) <0
    disp('Input image must scale to 0~1')
    return
end

   numTrain = 10000;
   dbn.sizes = [100 100 50];
   opts.numepochs =   1;
   opts.batchsize = 500;
   opts.momentum  =   0;
   opts.alpha     =   1;
   if nargin==3
    numTrain = params.numTrain-mod(params.numTrain,500)
    dbn.sizes = params.numLayerNodes;
    opts.numepochs =   params.numIters;
    opts.batchsize = 500;
    opts.momentum  =   params.momentum;
    opts.alpha     =   params.alpha;
    else if nargin>3
            disp('Input parameters wong');
            return;
        end
    end

fprintf('Sample train_x begin\n');
train_x = SamplePatches(img, rf,numTrain); % NxD
fprintf('Sample train_x finished\n');

dbn = dbnsetup(dbn, train_x, opts);
dbn = dbntrain(dbn, train_x, opts);

fvDim = dbn.sizes( length(dbn.sizes) );
imgFV = zeros(H,W,fvDim);

tmpImg = Img2PImg(img, rf);

for i=1:H
    tmpData = squeeze( tmpImg(i,:,:) ) ;
    tmpFV = UpDBN(tmpData', dbn);
    imgFV(i,:,:) = tmpFV';
end



end